package dao.impl;

import dao.DoctorDao;
import entity.Doctor;
import util.DoctorRowMapper;
import util.DruidUtils;

import java.util.List;


public class DoctorDaoImpl implements DoctorDao {

    @Override
    public List<Doctor> getAllDoctor() {
        String sql = "select * from t_doctor";
        return DruidUtils.commonsSelect(sql, new DoctorRowMapper(), new Object[]{});
    }

    @Override
    public List<Doctor> getByDoctorId(String id) {
        String sql = "select * from t_doctor where D_Id ='" + id + "'";
        return DruidUtils.commonsSelect(sql, new DoctorRowMapper(), new Object[]{});

    }

    @Override
    public List<Doctor> getByDoctorTel(String tel) {
        String sql = "select * from t_doctor where D_Tel ='" + tel + "'";
        return DruidUtils.commonsSelect(sql, new DoctorRowMapper(), new Object[]{});
    }

//          @Override
//        public String getPwdByDoctorId(String id) {
//            String sql="select * from t_doctor where D_Id ='"+id+"'";
//            List<Doctor> list = DruidUtils.commonsSelect(sql,new DoctorRowMapper(),new Object[]{});
//            String a=list.get(0).getPwd();
//            return a;
//
//    }

    @Override
    public int add(Doctor doctor) {

        String sql = "insert  into `t_doctor`(`D_Id`,`D_Pwd`,`D_Name`,`D_Tel`,`D_Sex`,`D_Edu`,`D_Joindate`,`AdminCheck`,`Other`,`D_Picture`,`D_Post`,`D_Email`) values (?,?,?,?,?,?,?,?,?,?,?,?)";
        //String sql = "insert  into `t_doctor`(`id`) values (?)";

        return DruidUtils.executeUpdate(sql, doctor.getId(), doctor.getPwd(), doctor.getName(), doctor.getTel(), doctor.getSex(), doctor.getEdu(), doctor.getJoindate(), doctor.getAdmincheck(), doctor.getOther(), doctor.getPicture(), doctor.getPost(), doctor.getEmail());
    }

    @Override
    public int delete(String doctorno) {
        String sql = "delete from t_doctor where D_Id = ?";

        return DruidUtils.executeUpdate(sql, doctorno);
    }

    @Override
    public int update(Doctor doctor) {

//        String sql = "update t_doctor set `pwd`=?,`name`=?,`tel`=?,`sex`=?,`edu`=?,`joindate`=?,`admincheck`=?,`other`=?,`picture`=?,`post`=? where `id`=?";
        String sql = "update t_doctor set `D_Pwd`=?,`D_Name`=?,`D_Tel`=?,`D_Sex`=?,`D_Edu`=?,`D_Joindate`=?,`AdminCheck`=?,`Other`=?,`D_Picture`=?,`D_Post`=?,`D_Email`=? where `D_Id`=?";
        //String sql = "insert  into `t_doctor`(`id`) values (?)";
        return DruidUtils.executeUpdate(sql, doctor.getPwd(), doctor.getName(), doctor.getTel(), doctor.getSex(), doctor.getEdu(), doctor.getJoindate(), doctor.getAdmincheck(), doctor.getOther(), doctor.getPicture(), doctor.getPost(), doctor.getEmail(), doctor.getId());
    }

    @Override
    public int updateNoPwd(Doctor doctor) {
        String sql = "update t_doctor set `D_Name`=?,`D_Tel`=?,`D_Sex`=?,`D_Edu`=?,`D_Joindate`=?,`AdminCheck`=?,`Other`=?,`D_Picture`=?,`D_Post`=?,`D_Email`=? where `D_Id`=?";
        return DruidUtils.executeUpdate(sql, doctor.getName(), doctor.getTel(), doctor.getSex(), doctor.getEdu(), doctor.getJoindate(), doctor.getAdmincheck(), doctor.getOther(), doctor.getPicture(), doctor.getPost(), doctor.getEmail(), doctor.getId());
    }

    @Override
    public int updateAdminCheck(String id, String adminCheck) {
        String sql = "update t_doctor set `AdminCheck`=? where `D_Id`=?";

        return DruidUtils.executeUpdate(sql, adminCheck, id);
    }
}